<?php
/*********************************************************************************
 * This file is part of KReporter. KReporter is an enhancement developed 
 * by KINAMU Business Solutions AG. All rights ar (c) 2010 by KINAMU Business
 * Solutions AG.
 *
 * KReporter is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * KReporter is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with KReporter.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * You can contact KINAMU Business Solutions AG at Am Concordepark 2/F12
 * A-2320 Schwechat or via email at office@kinamu.com
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU General Public License version 3,
 * these Appropriate Legal Notices must retain the Name KINAMU in the Name
 * of the Module which needs to be visible to the User.
 * 
 ********************************************************************************/
	require_once('modules/KReports/json/JSON.php');

 	function json_decode_kinamu($json)
	{ 
		
	    
	    $comment = false;
	    $out = '$x=';
	   
	    for ($i=0; $i<strlen($json); $i++)
	    {
	        if (!$comment)
	        {
	            if ($json[$i] == '{' or $json[$i] == '[')        $out .= ' array(';
	            else if ($json[$i] == '}' or $json[$i] == ']')    $out .= ')';
	            else if ($json[$i] == ':')    $out .= '=>';
	            else                         $out .= $json[$i];           
	        }
	        else $out .= $json[$i];
	        if ($json[$i] == '"')    $comment = !$comment;
	    }
	    eval($out . ';');
	    return $x;
	    
	}  
	
	function json_encode_kinamu($input)
	{
		$json = new Services_JSON();
		return $json->encode($input);
	}
	
	
	if(!function_exists('html_entity_decode_utf8'))
	{
		function html_entity_decode_utf8($string)
		{
		    static $trans_tbl;
		    
		    $string = preg_replace('~&#x([0-9a-f]+);~ei', 'code2utf(hexdec("\\1"))', $string);
		    $string = preg_replace('~&#([0-9]+);~e', 'code2utf(\\1)', $string);
		    
		    if (!isset($trans_tbl))
		    {
		        $trans_tbl = array();
		        foreach (get_html_translation_table(HTML_ENTITIES) as $val=>$key)
		            $trans_tbl[$key] = utf8_encode($val);
		    }
		    return strtr($string, $trans_tbl);
		}
	}
?>